﻿#region | Copyright © Siriwat Suananpornpanit 2556 |

/*
	##########################################################################
		Software Generator Code For Hashtable From Table Name => FUNCTION_APPLICATION
		Author By : Siriwat Suananpornpanit
		DateTime : 2556/08/22 11:58:08
	##########################################################################
	*/

#endregion

#region Class | Imports |

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using DataAccess.Interface;
using Microsoft.VisualBasic;
using System.Text;
using DataAccess.DBConnections;
using DataAccess.ProxyConnections;
using Oracle.DataAccess.Client;

#endregion

namespace DataAccess.Dal
{
    internal class FunctionApplicationDal //: IResponsible<Prop.FunctionApplication>
    {

        /* for DataBase Connection */

        private static DBConnectionsEngine dbEngine;

        private static OracleConnection Conn;

        private static Hashtable hashtable;


        private static FunctionApplicationDal _dal;

        private System.String sql = "";


        public static FunctionApplicationDal GetInstance()
        {
            /* for Init */

            dbEngine = new DBConnectionsEngine();

            Conn = new DatabaseProxy().GetAuthConnection();

            _dal = new FunctionApplicationDal();

            return _dal;
        }

        public IEnumerable<Prop.FunctionApplication> Select(Prop.FunctionApplication obj)
        {
            IEnumerable<Prop.FunctionApplication> entities = new List<Prop.FunctionApplication>();
            try
            {
                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.STATUS))
                    {
                        concast.Append(" AND STATUS=:STATUS ");
                        hashtable.Add(":STATUS", obj.STATUS);
                    }

                    if (!String.IsNullOrEmpty(obj.REMARK))
                    {
                        concast.Append(" AND REMARK=:REMARK ");
                        hashtable.Add(":REMARK", obj.REMARK);
                    }
                    
                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCNO))
                    {
                        concast.Append(" AND FUNCNO=:FUNCNO ");
                        hashtable.Add(":FUNCNO", obj.FUNCNO);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCNAME))
                    {
                        concast.Append(" AND FUNCNAME=:FUNCNAME ");
                        hashtable.Add(":FUNCNAME", obj.FUNCNAME);
                    }

                    if (!String.IsNullOrEmpty(obj.PARENTFUNC))
                    {
                        concast.Append(" AND PARENTFUNC=:PARENTFUNC ");
                        hashtable.Add(":PARENTFUNC", obj.PARENTFUNC);
                    }

                    if (!String.IsNullOrEmpty(obj.MAINSCREEN))
                    {
                        concast.Append(" AND MAINSCREEN=:MAINSCREEN ");
                        hashtable.Add(":MAINSCREEN", obj.MAINSCREEN);
                    }

                    if (!Information.IsNothing(obj.RUNNING_BY_PARENFUNC))
                    {
                        concast.Append(" AND RUNNING_BY_PARENFUNC=:RUNNING_BY_PARENFUNC ");
                        hashtable.Add(":RUNNING_BY_PARENFUNC", obj.RUNNING_BY_PARENFUNC);
                    }

                    if (!Information.IsNothing(obj.PDAFLAG))
                    {
                        concast.Append(" AND PDAFLAG=:PDAFLAG ");
                        hashtable.Add(":PDAFLAG", obj.PDAFLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.MOBILEURL))
                    {
                        concast.Append(" AND MOBILEURL=:MOBILEURL ");
                        hashtable.Add(":MOBILEURL", obj.MOBILEURL);
                    }

                }
                sql = System.String.Format(@" SELECT STATUS ,REMARK ,CRDATE ,CRBY ,UPDDATE ,UPDBY ,COMPANY_CODE ,APPLNO ,FUNCNO ,FUNCNAME ,PARENTFUNC ,MAINSCREEN ,RUNNING_BY_PARENFUNC ,PDAFLAG ,SEQMENU ,SEQSUBMENU1 ,SEQSUBMENU2 ,MOBILEURL  FROM FUNCTION_APPLICATION");

                sql = sql + concast.ToString();

                entities = dbEngine.ToList<Prop.FunctionApplication>(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                entities = null;
            }
            return entities;
        }

        public Boolean Add(Prop.FunctionApplication obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" INSERT INTO FUNCTION_APPLICATION(STATUS ,REMARK ,CRDATE ,CRBY ,UPDDATE ,UPDBY ,COMPANY_CODE ,APPLNO ,FUNCNO ,FUNCNAME ,PARENTFUNC ,MAINSCREEN ,RUNNING_BY_PARENFUNC ,PDAFLAG ,SEQMENU ,SEQSUBMENU1 ,SEQSUBMENU2 ,MOBILEURL )
					VALUES(:STATUS ,:REMARK ,:CRDATE ,:CRBY ,:UPDDATE ,:UPDBY ,:COMPANY_CODE ,:APPLNO ,:FUNCNO ,:FUNCNAME ,:PARENTFUNC ,:MAINSCREEN ,:RUNNING_BY_PARENFUNC ,:PDAFLAG ,:SEQMENU ,:SEQSUBMENU1 ,:SEQSUBMENU2 ,:MOBILEURL ");

                hashtable = new Hashtable();
                hashtable.Add(":STATUS", obj.STATUS);
                hashtable.Add(":REMARK", obj.REMARK);
                //hashtable.Add(":CRDATE", obj.CRDATE);
                //hashtable.Add(":CRBY", obj.CRBY);
                //hashtable.Add(":UPDDATE", obj.UPDDATE);
                //hashtable.Add(":UPDBY", obj.UPDBY);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":FUNCNO", obj.FUNCNO);
                hashtable.Add(":FUNCNAME", obj.FUNCNAME);
                hashtable.Add(":PARENTFUNC", obj.PARENTFUNC);
                hashtable.Add(":MAINSCREEN", obj.MAINSCREEN);
                hashtable.Add(":RUNNING_BY_PARENFUNC", obj.RUNNING_BY_PARENFUNC);
                hashtable.Add(":PDAFLAG", obj.PDAFLAG);
                //hashtable.Add(":SEQMENU", obj.SEQMENU);
                //hashtable.Add(":SEQSUBMENU1", obj.SEQSUBMENU1);
                //hashtable.Add(":SEQSUBMENU2", obj.SEQSUBMENU2);
                hashtable.Add(":MOBILEURL", obj.MOBILEURL);
                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Update(Prop.FunctionApplication obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" UPDATE FUNCTION_APPLICATION
					SET
					STATUS=:STATUS,
					REMARK=:REMARK,
					CRDATE=:CRDATE,
					CRBY=:CRBY,
					UPDDATE=:UPDDATE,
					UPDBY=:UPDBY,
					COMPANY_CODE=:COMPANY_CODE,
					APPLNO=:APPLNO,
					FUNCNO=:FUNCNO,
					FUNCNAME=:FUNCNAME,
					PARENTFUNC=:PARENTFUNC,
					MAINSCREEN=:MAINSCREEN,
					RUNNING_BY_PARENFUNC=:RUNNING_BY_PARENFUNC,
					PDAFLAG=:PDAFLAG,
					SEQMENU=:SEQMENU,
					SEQSUBMENU1=:SEQSUBMENU1,
					SEQSUBMENU2=:SEQSUBMENU2,
					MOBILEURL=:MOBILEURL");

                hashtable = new Hashtable();
                hashtable.Add(":STATUS", obj.STATUS);
                hashtable.Add(":REMARK", obj.REMARK);
                //hashtable.Add(":CRDATE", obj.CRDATE);
               // hashtable.Add(":CRBY", obj.CRBY);
                //hashtable.Add(":UPDDATE", obj.UPDDATE);
                //hashtable.Add(":UPDBY", obj.UPDBY);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":FUNCNO", obj.FUNCNO);
                hashtable.Add(":FUNCNAME", obj.FUNCNAME);
                hashtable.Add(":PARENTFUNC", obj.PARENTFUNC);
                hashtable.Add(":MAINSCREEN", obj.MAINSCREEN);
                hashtable.Add(":RUNNING_BY_PARENFUNC", obj.RUNNING_BY_PARENFUNC);
                hashtable.Add(":PDAFLAG", obj.PDAFLAG);
                //hashtable.Add(":SEQMENU", obj.SEQMENU);
                //hashtable.Add(":SEQSUBMENU1", obj.SEQSUBMENU1);
                //hashtable.Add(":SEQSUBMENU2", obj.SEQSUBMENU2);
                hashtable.Add(":MOBILEURL", obj.MOBILEURL);

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Delete(Prop.FunctionApplication obj)
        {
            Boolean result = false;
            try
            {

                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.STATUS))
                    {
                        concast.Append(" AND STATUS=:STATUS ");
                        hashtable.Add(":STATUS", obj.STATUS);
                    }

                    if (!String.IsNullOrEmpty(obj.REMARK))
                    {
                        concast.Append(" AND REMARK=:REMARK ");
                        hashtable.Add(":REMARK", obj.REMARK);
                    }
                    /*
                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.CRBY))
                    {
                        concast.Append(" AND CRBY=:CRBY ");
                        hashtable.Add(":CRBY", obj.CRBY);
                    }

                    if (!Information.IsDate(obj.UPDDATE))
                    {
                        concast.Append(" AND UPDDATE=:UPDDATE ");
                        hashtable.Add(":UPDDATE", obj.UPDDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.UPDBY))
                    {
                        concast.Append(" AND UPDBY=:UPDBY ");
                        hashtable.Add(":UPDBY", obj.UPDBY);
                    }
                    */
                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCNO))
                    {
                        concast.Append(" AND FUNCNO=:FUNCNO ");
                        hashtable.Add(":FUNCNO", obj.FUNCNO);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCNAME))
                    {
                        concast.Append(" AND FUNCNAME=:FUNCNAME ");
                        hashtable.Add(":FUNCNAME", obj.FUNCNAME);
                    }

                    if (!String.IsNullOrEmpty(obj.PARENTFUNC))
                    {
                        concast.Append(" AND PARENTFUNC=:PARENTFUNC ");
                        hashtable.Add(":PARENTFUNC", obj.PARENTFUNC);
                    }

                    if (!String.IsNullOrEmpty(obj.MAINSCREEN))
                    {
                        concast.Append(" AND MAINSCREEN=:MAINSCREEN ");
                        hashtable.Add(":MAINSCREEN", obj.MAINSCREEN);
                    }

                    if (!Information.IsNothing(obj.RUNNING_BY_PARENFUNC))
                    {
                        concast.Append(" AND RUNNING_BY_PARENFUNC=:RUNNING_BY_PARENFUNC ");
                        hashtable.Add(":RUNNING_BY_PARENFUNC", obj.RUNNING_BY_PARENFUNC);
                    }

                    if (!Information.IsNothing(obj.PDAFLAG))
                    {
                        concast.Append(" AND PDAFLAG=:PDAFLAG ");
                        hashtable.Add(":PDAFLAG", obj.PDAFLAG);
                    }
                    /*
                    if (!Information.IsNothing(obj.SEQMENU))
                    {
                        concast.Append(" AND SEQMENU=:SEQMENU ");
                        hashtable.Add(":SEQMENU", obj.SEQMENU);
                    }

                    if (!Information.IsNothing(obj.SEQSUBMENU1))
                    {
                        concast.Append(" AND SEQSUBMENU1=:SEQSUBMENU1 ");
                        hashtable.Add(":SEQSUBMENU1", obj.SEQSUBMENU1);
                    }

                    if (!Information.IsNothing(obj.SEQSUBMENU2))
                    {
                        concast.Append(" AND SEQSUBMENU2=:SEQSUBMENU2 ");
                        hashtable.Add(":SEQSUBMENU2", obj.SEQSUBMENU2);
                    }
                    */
                    if (!String.IsNullOrEmpty(obj.MOBILEURL))
                    {
                        concast.Append(" AND MOBILEURL=:MOBILEURL ");
                        hashtable.Add(":MOBILEURL", obj.MOBILEURL);
                    }

                }
                sql = System.String.Format(@" DELETE FROM FUNCTION_APPLICATION ");

                sql = sql + concast.ToString();

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

    }
}

/*
##########################################################################
    Free Software License
##########################################################################
*/